package com.ereport.controller.reportsController;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.ereport.dao.ConveyanceExpDAO;
import com.ereport.entity.Executives;
import com.ereport.entity.Expenses;


@Controller
@RequestMapping("/conveyExpdture")
public class ConveyanceExpenditureReport {
	@RequestMapping(value="/open.do", method=RequestMethod.GET)
	public ModelAndView open(HttpServletRequest req,HttpSession session,ModelAndView model){
		Executives ex=(Executives)session.getAttribute("loginUser");
		if(ex==null){
			model.setViewName("/jsp/login.jsp");
			return model;
		}
		
		model.setViewName("/jsp/convExpndtureReport.jsp");
		return model;
	}
	@RequestMapping(value="/getExpReport.do", method=RequestMethod.POST)
	public ModelAndView getExpReport(HttpServletRequest req,HttpSession session,ModelAndView model){
		Executives ex=(Executives)session.getAttribute("loginUser");
		if(ex==null){
			model.setViewName("/jsp/login.jsp");
			return model;
		}
		String mnth=req.getParameter("month");
		System.out.println("month "+mnth);
		
		String yr=req.getParameter("year");
		
		ConveyanceExpDAO cedao=new ConveyanceExpDAO();
		List<Expenses> osList=null;
		try {
			osList=cedao.getExpRep(ex.getId(),mnth,yr);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		session.setAttribute("year", yr);
		session.setAttribute("mnth",mnth);
		session.setAttribute("expList",osList);
		model.setViewName("redirect:open.do");
		return model;
	}
}
